#ifndef __MYSQL_PROTOCOL_H__
#define __MYSQL_PROTOCOL_H__

#include <memory>
#include <map>

namespace secsmart_tcpip
{
    class IPAddress;
}

namespace dbdetect
{
    class MySQLProtocol
    {
    public:
        MySQLProtocol(std::string& targetFileName, bool checkCompress, int32_t maxth);
        ~MySQLProtocol(){};

        uint16_t get_proto_type() { return proto_type_; }
        int32_t dissector(const uint8_t *buf, size_t size);
        void set_proto_type();
        void set_proto_version(const char* ver);
        std::string& get_proto_version() { return proto_version_; }
        void setHashDBTypeMap(size_t socketHash);
        bool isSocketInMap(size_t socketHash);
        bool writeTargetFile(secsmart_tcpip::IPAddress& sip, secsmart_tcpip::IPAddress& dip, uint16_t sport, uint16_t dport, bool s2c);
        bool checkIfTheDataIsCompressed(const uint8_t* data);
        uint32_t getMaxThreshold() { return maxThreshold_; }    

    private:
        uint16_t proto_type_;
        uint32_t packet_number_ = 0;
        size_t left_length_ = 0;
        int32_t default_state_ = 0;
        std::map<size_t, uint16_t> parsed_DB_map_;
        std::string targetFileName_;
        std::string proto_version_;
        bool checkCompress_;
        uint32_t maxThreshold_;
        uint16_t phase_ = PHASE_HALF_LINK;
        bool gotLoginReq_ = false;
    };
    

}; // namespace dbdtect

#endif